package cn.psvmc.cxzapi.config.mybatisplus.injector;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.extension.injector.methods.AlwaysUpdateSomeColumnById;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description：自定义SQL注入器
 * @Author: WN
 * @Date: 2023/8/3 20:06:20
 **/
@Component
public class MybatisPlusSqlInjector extends DefaultSqlInjector {
    @Override
    public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
        // 拿到父类的getMethodList方法
        List<AbstractMethod> methodList = super.getMethodList(mapperClass,tableInfo);
        
        methodList.add(new AlwaysUpdateSomeColumnById(i -> i.getFieldFill() != FieldFill.INSERT));
        // methodList.add(new InsertBatchSomeColumn(i -> i.getFieldFill() != FieldFill.UPDATE));
        methodList.add(new InsertBatchSomeColumn("insertBatchSomeColumn"));

        return methodList;
    }
}
